<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: pink;
        }

        .chang {
            width: 100px;
            height: 100px;
            margin: 100px auto;
            background-color: red;
        }
    </style>
</head>

<body>

    <div class="frest">文本</div>

    <script>
        //1.获取元素
        var div = document.querySelector('div');
        div.onclick = function () {

            //我们可以通过 修改元素classname更改元素的样式
            // this.className = 'chang';
            //在原基础上加个 chang
            this.className = 'frest chang'
        }

    </script>
</body>

</html>